package com.sumainfor.wx.system.gmio.controller;

import com.qiniu.util.Auth;
import com.sumainfor.common.NiuYunToken;
import com.sumainfor.common.util.JsonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Meng
 * @ClassName QiNiuYunController
 * @date 2019/8/22 15:51
 * @description: TODO 获取七牛云token
 */
@RestController
public class QiNiuYunController {

    @GetMapping("/NiuYun/Token")
    public JsonResult saveNiuYunToken() throws Exception {
        JsonResult result = new JsonResult();
        Map<String, Object> qiniu = new HashMap<String, Object>();
        try {
            Auth auth = Auth.create(NiuYunToken.QINIU_ACCESS_KEY, NiuYunToken.QINIU_SECRET_Key);
            String upToken = auth.uploadToken(NiuYunToken.publicBucketname);
            qiniu.put("token", upToken);
            qiniu.put("url", NiuYunToken.publicQiniuUrl);
            result.put(qiniu);
        } catch (Exception e) {
            System.out.println(e);
            result.putFailed("服务器繁忙,请稍后重试！");
        }
        return result;

    }
}
